package com.qf.business.message.utils;

import com.qf.business.message.entity.Rooms;
import com.qf.commons.core.utils.ApplicationUtils;
import org.kurento.client.KurentoClient;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 房间管理类
 * author Ken
 * create_time 2023/1/6
 */
public class RoomUtils {

    private static Map<Long, Rooms> roomsMap = new ConcurrentHashMap<>();

    /**
     * 根据课程号 - 获取房间对象
     * @param cid
     * @return
     */
    public static Rooms getRooms(Long cid, String cname){
        //获取房间对象
        Rooms rooms = roomsMap.get(cid);
        if(rooms == null){
            //创建房间
            rooms = new Rooms()
                    .setCid(cid)
                    .setCname(cname)
                    .setMediaPipeline(ApplicationUtils.getBean(KurentoClient.class).createMediaPipeline());
            roomsMap.put(cid, rooms);
        }
        return rooms;
    }

    /**
     * 根据当前的课程号，移除房间
     * @param cid
     * @return
     */
    public static Rooms removeRooms(Long cid){
        Rooms rooms = roomsMap.remove(cid);
        return rooms;
    }
}
